#ifndef _MAINFORM_H_
#define _MAINFORM_H_

#include <FBase.h>
#include <FUi.h>
#include <FMedia.h>

#include "DatabaseHandler.h"

class MainForm :
	public Osp::Ui::Controls::Form,
	public Osp::Ui::IActionEventListener,
	public Osp::Ui::ICustomItemEventListener
{

// Construction
public:
	MainForm(void);
	virtual ~MainForm(void);
	bool Initialize(void);

	DatabaseHandler databasehandler;

// Implementation
protected:

	// main form resources
	Osp::Ui::Controls::CustomList *__pList;
	Osp::Ui::Controls::CustomListItemFormat * __pCustomListItemFormat;
	Osp::Ui::Controls::OptionMenu *__pOptionsMenu;

	// image resources
	Osp::Graphics::Bitmap * bitmapDeletePassive;
	Osp::Graphics::Bitmap * bitmapDeleteActive;

	// addpopup resources
	Osp::Ui::Controls::Popup *__pNewRowModal;
	Osp::Ui::Controls::Button *__pAddButton;
	Osp::Ui::Controls::Button *__pCloseAddButton;
	Osp::Ui::Controls::EditField *__pNameEditField;
	Osp::Ui::Controls::EditField *__pPwdEditField;

	// Action ID-s
	static const int NEW_MODAL_ADD = 102;
	static const int NEW_MODAL_X = 103;
	static const int PAGE_LEFT = 105;
	static const int PAGE_RIGHT = 106;
	static const int NEW_MODAL_START = 101;
	static const int LIST_ID = 104;
	static const int TEXT_LISTENER = 107;
	static const int DELETE_LISTENER = 108;
	static const int OPTION_KEY_ACTION = 201;
	static const int SORT_ASC = 202;
	static const int SORT_DESC = 203;

	// other resources
	Osp::Base::Collection::ArrayListT<Osp::Base::String> arraylist;
	Osp::Io::DbEnumerator * enumerator;
	int currentPage;
	int rowsPerPage;
	bool sort;

public:
	virtual result OnInitializing(void);
	virtual result OnTerminating(void);
	virtual void OnActionPerformed(const Osp::Ui::Control& source, int actionId);

	void OnItemStateChanged(const Osp::Ui::Control& source, int index, int itemId, int elementId, Osp::Ui::ItemStatus status);
	void OnItemStateChanged(const Osp::Ui::Control& source, int index, int itemId, Osp::Ui::ItemStatus status);

private:
	void RefreshList(bool sorrend);
};

#endif	//_MAINFORM_H_
